//
//  HWGameDetailOpenServiceCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/3/25.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWGameDetailOpenServiceCell: UITableViewCell {
    var bgView:UIView!
    var timeLabel:UILabel!
    var serviceLabel:UILabel!
    var typeLabel:UILabel!
    var model:HWGameDetailOpenServiceModel?{
        didSet {
            timeLabel.text = (model?.time1 ?? "") + "  " + (model?.time2 ?? "")
            serviceLabel.text = model?.server_name
            typeLabel.text = model?.type
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWGameDetailOpenServiceCell) {
        let reUse:String = "HWGameDetailOpenServiceCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWGameDetailOpenServiceCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWGameDetailOpenServiceCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        bgView = UIView()
        bgView.backgroundColor = .colorWithHexString(hexString: "#FFF1E4")
        bgView.layer.borderColor = UIColor.colorWithHexString(hexString: "#F87706").cgColor
        bgView.layer.borderWidth = 1
        bgView.layer.cornerRadius = 15*widthScale
        contentView.addSubview(bgView)
        
        timeLabel = HWLabel.createLabel(title: "", color: "#444444", font: 12*widthScale)
        bgView.addSubview(timeLabel)
        
        serviceLabel = HWLabel.createBoldLabel(title: "", color: "#F66A05", font: 12*widthScale)
        bgView.addSubview(serviceLabel)
        
        typeLabel = HWLabel.createLabel(title: "", color: "#888888", font: 10*widthScale)
        bgView.addSubview(typeLabel)
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.bottom.equalTo(-10*widthScale)
            make.left.equalTo(12*widthScale)
            make.right.equalTo(-12*widthScale)
            make.height.equalTo(30*widthScale)
        }
        
        timeLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(10*widthScale)
        }
        
        typeLabel.snp.makeConstraints { make in
            make.right.equalTo(-10*widthScale)
            make.centerY.equalToSuperview()
        }
        
        serviceLabel.snp.makeConstraints { make in
            make.right.equalTo(typeLabel.snp.left).offset(-10*widthScale)
            make.centerY.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
